package com.example.taxfloatproject20240926.ui.busevent;

import android.os.Handler;
import android.os.Looper;

import com.squareup.otto.Bus;
import com.squareup.otto.ThreadEnforcer;

public class PostFromAnyThreadBus extends Bus {

	public PostFromAnyThreadBus() {
		super(ThreadEnforcer.MAIN);
	}

	@Override
	public void post(final Object event) {
		if (Looper.myLooper() != Looper.getMainLooper()) {
			(new Handler(Looper.getMainLooper())).post(new Runnable() {

				@Override
				public void run() {
					PostFromAnyThreadBus.super.post(event);
				}
			});
		} else {
			super.post(event);
		}

	}

	@Override
	public void unregister(Object object) {
		try {
			super.unregister(object);
		} catch (Exception e) {
		}
	}

}
